package org.nado.member;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

@Service
@Controller("RegistInterceptor")
public class RegistInterceptor extends HandlerInterceptorAdapter {
		
		private static final Logger logger = Logger.getLogger("RegistInterceptor");

		@Override
		public boolean preHandle(HttpServletRequest request,
				HttpServletResponse response, Object hadler) throws Exception {
			
			HttpSession session = request.getSession();
			
					
			logger.info("RegistInterceptor........................");

			if (session == null) {
				return true;

			}
			try {
				MemberVO vo = (MemberVO) session.getAttribute("loginInfo");
				if (vo.getMem_id() == null) {
					return true;
				}
			} catch (Exception e) {
				response.sendRedirect("member/main.jsp");
			}
			response.sendRedirect("member/main.jsp");
			return false;
		}


		@Override
		public void afterCompletion(HttpServletRequest request,
				HttpServletResponse response, Object hadler, Exception arg3)
				throws Exception {
			// TODO Auto-generated method stub

		}

		@Override
		public void postHandle(HttpServletRequest request, HttpServletResponse response,
				Object hadler, ModelAndView mav) throws Exception {
			// TODO Auto-generated method stub

		}


}
